<?php
/**
 * Created by PhpStorm.
 * User: wenlei
 * Date: 16/5/8
 * Time: 下午8:51
 */

namespace App\Http\Controllers\Console;
use App\Model\CheckRequest;
use App\Model\CheckResult;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Request;
use App\Http\Controllers\Controller;

class SendCheckRequestController extends Controller
{
    public function indexAction() {

        $url='localhost:8000/command/checkdata';
        $datatype = Request::input('datatype');
        $time  = Request::input('time');
        $sTime = Request::input('sTime');
        $eTime = Request::input('eTime');
        $checkMethod = Request::input('checkMethod');
        $modelType = Request::input('modelType');

        if($time){
            $method = 'PointInTime';
            $a=CheckRequest::query()->where('DataType',$datatype)->where('CheckMethod',$checkMethod)->where('Model_IDs',$modelType)->where('STime',$time)->orderBy('Request_Time','desc')->first();
        }else{
            $method = 'Period';
            $a=CheckRequest::query()->where('DataType',$datatype)->where('CheckMethod',$checkMethod)->where('Model_IDs',$modelType)->where('STime',$sTime)->where('ETime',$eTime)->orderBy('Request_Time','desc')->first();
        }

        if(count($a)>0){
            if($a['IsCheckOver'] ==1){
                $b=CheckResult::query()->where('Check_ID',$a['ID'])->get();
                if($b['IsSuccess'] == 1){
                    //整合数据
                    return $this->successForJson($data);
                }else{
                    //
                    $this->doRequest($url);
                    return $this->successForJson();
                }
            }else{
                return $this->successForJson('正在检验');
            }
        }else{
            $this->doRequest($url);
            return $this->successForJson('开始检验');
        }
    }
}